<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.name"
          clearable
          size="small"
          placeholder="输入公司名称"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud"/>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" :path="path" :upload-url="uploadUrl" />
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" border height="550" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" fixed />
        <el-table-column v-if="columns.visible('companyName')" fixed prop="companyName" label="公司名称" />
        <el-table-column v-if="columns.visible('partnerType')" fixed prop="partnerType" label="合作伙伴类型">
          <template slot-scope="scope">
            <span>
              {{ dict.label.ict_partner_type[scope.row.partnerType] }}
            </span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('companyLocation')" prop="companyLocation" label="公司所在地" />
        <el-table-column v-if="columns.visible('province')" prop="province" label="省份">
          <template slot-scope="scope">
            <span>
              {{ dict.label.ict_partner_province[scope.row.province] }}
            </span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('registrationDate')" prop="registrationDate" label="公司注册时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.registrationDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('employeeCount')" prop="employeeCount" label="公司员工数" />
        <el-table-column v-if="columns.visible('oneYearSales')" prop="oneYearSales" label="公司近一年销售额" />
        <el-table-column v-if="columns.visible('contactName')" prop="contactName" label="联系人姓名" />
        <el-table-column v-if="columns.visible('contactPosition')" prop="contactPosition" label="联系人职务" />
        <el-table-column v-if="columns.visible('contactNumber')" prop="contactNumber" label="联系人电话" />
        <el-table-column v-if="columns.visible('contactMailbox')" prop="contactMailbox" label="联系人邮箱" />
        <el-table-column v-if="columns.visible('companyWebsite')" prop="companyWebsite" label="公司网址" />
        <el-table-column v-if="columns.visible('remarks')" prop="remarks" label="备注信息" />
        <el-table-column v-permission="['admin','ictPartner:edit','ictPartner:del']" fixed="right" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <ud
              :path="path"
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudIctPartner from '@/api/ict/ictPartner/ictPartner'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.ict'
import pagination from '@crud/Pagination'
import ud from '@crud/UD.ict'

// crud交由presenter持有
const defaultCrud = CRUD({ title: 'ICT合作伙伴', url: 'api/ictPartner', sort: 'id,desc', crudMethod: { ...crudIctPartner }})
const defaultForm = { id: null, companyName: null, companyLocation: null, province: null, introduction: null, registrationDate: null, employeeCount: null, oneYearSales: null, contactName: null, contactPosition: null, contactNumber: null, contactMailbox: null, companyWebsite: null, companyIntroductionMaterials: null, createBy: null, createDate: null, updateBy: null, updateDate: null, remarks: null, delFlag: null }
export default {
  name: 'IctPartner',
  components: { pagination, crudOperation, rrOperation, ud },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['ict_partner_province', 'ict_partner_type'],
  data() {
    return {
      path: '/ict/ictPartner/form',
      uploadUrl: '/api/ictPartner/import',
      permission: {
        add: ['admin', 'ictPartner:add'],
        edit: ['admin', 'ictPartner:edit'],
        del: ['admin', 'ictPartner:del']
      },
      rules: {
        id: [
          { required: true, message: '合作伙伴ID不能为空', trigger: 'blur' }
        ],
        companyName: [
          { required: true, message: '公司名称不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 获取数据后对数据进行二次处理
    [CRUD.HOOK.afterRefresh]() {

    }
  }
}
</script>

<style scoped>

</style>
